ToNumber and CDbl are equivalent functions.
ToNumber converts a Number, Currency, text string, or Boolean value to a Number.
In a database, some numbers are stored in numeric fields, as Numbers, and some are stored in character fields, as text. You make the determination which fields are to be numeric and which are to be text when you set up the database in the first place. Numbers on which you might wish to perform arithmetic (item cost, quantity ordered, etc.) are typically stored in numeric fields; numbers on which you do not expect to perform arithmetic (customer number, telephone number, etc.) are typically stored in text objects.
ToNumber allows you to convert a Number stored as text to a Number on which you can perform arithmetic.
The Boolean argument enables you to treat SQL_BIT data values as if they were numbers.
You might use this function, for example, if your item numbers contain coded product information and you want to use that information in calculations. Typically, you would be using this function to convert a Currency or String value that contains all numeric characters to a Number type value.
The following examples are applicable to both Basic and Crystal syntax:
ToNumber({orders.ORDER AMOUNT})
Returns a Number type value that the Currency field {orders.ORDER AMOUNT} contains.
Returns 200.00 where "200" is the text string in the {file.REFERENCE} field.
Returns 22144 where {file.ACCTNO} = 44288.
ToNumber({customers.POSTAL CODE}) < 33333
Returns TRUE where {customer.POSTAL CODE} is "21385".
When using the ToNumber function, you should first test the value with the NumericText function. NumericText returns a value of TRUE only if the value in the string can be correctly converted to a Number. Otherwise, if you try to convert a value to a Number that is not a Number, the formula will produce an error in your report.
The following example is a common use of the NumericText and ToNumber functions together, in Crystal syntax:
If NumericText ({file.FIELD}) Then
Seagate Software IMG Holdings, Inc. http://www.seagatesoftware.com Support services: http://support.seagatesoftware.com |